﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
using System.IO;
using KPIS.GERP.GFMS.IBLL;
using KPIS.GERP.GFMS.BLL;
using KPIS.GERP.GFMS.DAL;
using KPIS.GERP.GFMS.MODEL;

using KPIS.GERP.GFMS.APP.App_UI.Commons;

namespace KPIS.GERP.GFMS.APP.App_UI.Forms
{
    public partial class FIM_MAS_CalulateTaxs : System.Web.UI.Page
    {
        Main main = new Main();
        IBLL_FIM_MAS_CalulateTaxs tax = new B_FIM_MAS_CalulateTaxs();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtPayYear.Text = (DateTime.Today.Year + 543).ToString();
                txtDupPayYear.Text = (DateTime.Today.Year + 542).ToString();
                LoadData(txtPayYear.Text);
            }
        }

        protected void LoadData(string strYear)
        {
            M_FIM_MAS_CalulateTaxs info = tax.GetInfoFromYear(strYear);

            if (info.pay_year != null)
            {
                lblEmpTaxSeq.Text = info.cal_tax_seq.ToString();
                txtChildCount.Text = info.child_count.ToString();
                txtChildEdu.Text = info.child_edu.ToString();
                txtChildNonEdu.Text = info.child_non_edu.ToString();
                txtContributePerMax.Text = info.contribute_per_max.ToString();
                txtDisabled.Text = info.disabled.ToString();
                txtExpenseMax.Text = info.expense_max.ToString();
                txtExpensePer.Text = info.expense_per.ToString();
                txtIns1Max.Text = info.ins_1_max.ToString();
                txtIns2Max.Text = info.ins_2_max.ToString();
                txtLoanMax.Text = info.loan_max.ToString();
                txtLtfMax.Text = info.ltf_max.ToString();
                txtLtfPerMax.Text = info.ltf_per_max.ToString();
                txtOverAge.Text = info.over_age.ToString();
                txtOverAgeAmount.Text = info.over_age_amount.ToString();
                txtParent.Text = info.parent.ToString();
                txtParentInsMax.Text = info.parent_ins_max.ToString();
                txtReduce.Text = info.reduce.ToString();
                txtReserve1Max.Text = info.reserve_1_max.ToString();
                txtReserve2Max.Text = info.reserve_2_max.ToString();
                txtReserve2PerMax.Text = info.reserve_2_per_max.ToString();
                txtReserveGovOfficeMax.Text = info.reserve_gov_office_max.ToString();
                txtRmfMax.Text = info.rmf_max.ToString();
                txtRmfPerMax.Text = info.rmf_per_max.ToString();
                txtSubEduPer.Text = info.sup_edu_per.ToString();
                txtSubEduPerMax.Text = info.sup_edu_per_max.ToString();
                txtSubSportPer.Text = info.sup_sport_per.ToString();
                txtSubSportPerMax.Text = info.sup_sport_per_max.ToString();
                txtTaxMax1.Text = info.tax_max1.ToString();
                txtTaxMax2.Text = info.tax_max2.ToString();
                txtTaxMax3.Text = info.tax_max3.ToString();
                txtTaxMax4.Text = info.tax_max4.ToString();
                txtTaxMax5.Text = info.tax_max5.ToString();
                txtTaxPer1.Text = info.tax_per1.ToString();
                txtTaxPer2.Text = info.tax_per2.ToString();
                txtTaxPer3.Text = info.tax_per3.ToString();
                txtTaxPer4.Text = info.tax_per4.ToString();
                txtTaxPer5.Text = info.tax_per5.ToString();

                cmdInsert.Visible = false;
                cmdUpdate.Visible = true;
            }
            else
            {
                ClearControl1();

                cmdInsert.Visible = true;
                cmdUpdate.Visible = false;
            }
        }

        protected void ClearControl1()
        {
            lblEmpTaxSeq.Text = "";
            txtExpensePer.Text = "";
            txtExpenseMax.Text = "";
            txtSubEduPer.Text = "";
            txtSubEduPerMax.Text = "";
            txtSubSportPer.Text = "";
            txtSubSportPerMax.Text = "";
            txtContributePerMax.Text = "";
            txtReserve2Max.Text = "";
            txtReserve2PerMax.Text = "";
            txtReserveGovOfficeMax.Text = "";
            txtOverAgeAmount.Text = "";
            txtOverAge.Text = "";
            txtIns2Max.Text = "";
            txtReduce.Text = "";
            txtChildEdu.Text = "";
            txtChildNonEdu.Text = "";
            txtChildCount.Text = "";
            txtParent.Text = "";
            txtParentInsMax.Text = "";
            txtDisabled.Text = "";
            txtIns1Max.Text = "";
            txtReserve1Max.Text = "";
            txtRmfPerMax.Text = "";
            txtRmfMax.Text = "";
            txtLtfPerMax.Text = "";
            txtLtfMax.Text = "";
            txtLoanMax.Text = "";
            txtTaxMax1.Text = "";
            txtTaxMax2.Text = "";
            txtTaxMax3.Text = "";
            txtTaxMax4.Text = "";
            txtTaxMax5.Text = "";
            txtTaxPer1.Text = "";
            txtTaxPer2.Text = "";
            txtTaxPer3.Text = "";
            txtTaxPer4.Text = "";
            txtTaxPer5.Text = "";
        }

        //============================ control events ==============================

        protected void cmdInsert_Click(object sender, EventArgs e)
        {
            M_FIM_MAS_CalulateTaxs info = new M_FIM_MAS_CalulateTaxs();
            //string strEmpTaxSeq = lblEmpTaxSeq.Text;
            string strPayYear = txtPayYear.Text;
            string strChildCount = txtChildCount.Text;
            string strChildEdu = txtChildEdu.Text;
            string strChildNonEdu = txtChildNonEdu.Text;
            string strContributePerMax = txtContributePerMax.Text;
            string strDisabled = txtDisabled.Text;
            string strExpenseMax = txtExpenseMax.Text;
            string strExpensePer = txtExpensePer.Text;
            string strIns1Max = txtIns1Max.Text;
            string strIns2Max = txtIns2Max.Text;
            string strLoanMax = txtLoanMax.Text;
            string strLtfMax = txtLtfMax.Text;
            string strLtfPerMax = txtLtfPerMax.Text;
            string strOverAge = txtOverAge.Text;
            string strOverAgeAmount = txtOverAgeAmount.Text;
            string strParent = txtParent.Text;
            string strParentInsMax = txtParentInsMax.Text;
            string strReduce = txtReduce.Text;
            string strReserve1Max = txtReserve1Max.Text;
            string strReserve2Max = txtReserve2Max.Text;
            string strReserve2PerMax = txtReserve2PerMax.Text;
            string strReserveGovOfficeMax = txtReserveGovOfficeMax.Text;
            string strRmfMax = txtRmfMax.Text;
            string strRmfPerMax = txtRmfPerMax.Text;
            string strSubEduPer = txtSubEduPer.Text;
            string strSubEduPerMax = txtSubEduPerMax.Text;
            string strSubSportPer = txtSubSportPer.Text;
            string strSubSportPerMax = txtSubSportPerMax.Text;
            string strTaxMax1 = txtTaxMax1.Text;
            string strTaxMax2 = txtTaxMax2.Text;
            string strTaxMax3 = txtTaxMax3.Text;
            string strTaxMax4 = txtTaxMax4.Text;
            string strTaxMax5 = txtTaxMax5.Text;
            string strTaxPer1 = txtTaxPer1.Text;
            string strTaxPer2 = txtTaxPer2.Text;
            string strTaxPer3 = txtTaxPer3.Text;
            string strTaxPer4 = txtTaxPer4.Text;
            string strTaxPer5 = txtTaxPer5.Text;
            string strUserID = Session["EmpSeq"].ToString();
            DateTime dtNow = DateTime.Now;

            info.child_count = main.ConvertNullInt(strChildCount);
            info.child_edu = main.ConvertNullDouble(strChildEdu);
            info.child_non_edu = main.ConvertNullDouble(strChildNonEdu);
            info.contribute_per_max = main.ConvertNullDouble(strContributePerMax);
            info.disabled = main.ConvertNullDouble(strDisabled);
            info.expense_max = main.ConvertNullDouble(strExpenseMax);
            info.expense_per = main.ConvertNullDouble(strExpensePer);
            info.ins_1_max = main.ConvertNullDouble(strIns1Max);
            info.ins_2_max = main.ConvertNullDouble(strIns2Max);
            info.loan_max = main.ConvertNullDouble(strLoanMax);
            info.ltf_max = main.ConvertNullDouble(strLtfMax);
            info.ltf_per_max = main.ConvertNullDouble(strLtfPerMax);
            info.over_age = main.ConvertNullInt(strOverAge);
            info.over_age_amount = main.ConvertNullDouble(strOverAgeAmount);
            info.parent = main.ConvertNullDouble(strParent);
            info.parent_ins_max = main.ConvertNullDouble(strParentInsMax);
            info.pay_year = main.ConvertNullInt(strPayYear);
            info.reduce = main.ConvertNullDouble(strReduce);
            info.reserve_1_max = main.ConvertNullDouble(strReserve1Max);
            info.reserve_2_max = main.ConvertNullDouble(strReserve2Max);
            info.reserve_2_per_max = main.ConvertNullDouble(strReserve2PerMax);
            info.reserve_gov_office_max = main.ConvertNullDouble(strReserveGovOfficeMax);
            info.reserve_teacher_max = 0;
            info.rmf_max = main.ConvertNullDouble(strRmfMax);
            info.rmf_per_max = main.ConvertNullDouble(strRmfPerMax);
            info.sup_edu_per = main.ConvertNullDouble(strSubEduPer);
            info.sup_edu_per_max = main.ConvertNullDouble(strSubEduPerMax);
            info.sup_sport_per = main.ConvertNullDouble(strSubSportPer);
            info.sup_sport_per_max = main.ConvertNullDouble(strSubSportPerMax);
            info.tax_max1 = main.ConvertNullDouble(strTaxMax1);
            info.tax_max2 = main.ConvertNullDouble(strTaxMax2);
            info.tax_max3 = main.ConvertNullDouble(strTaxMax3);
            info.tax_max4 = main.ConvertNullDouble(strTaxMax4);
            info.tax_max5 = main.ConvertNullDouble(strTaxMax5);
            info.tax_per1 = main.ConvertNullDouble(strTaxPer1);
            info.tax_per2 = main.ConvertNullDouble(strTaxPer2);
            info.tax_per3 = main.ConvertNullDouble(strTaxPer3);
            info.tax_per4 = main.ConvertNullDouble(strTaxPer4);
            info.tax_per5 = main.ConvertNullDouble(strTaxPer5);

            info.created_by = main.ConvertNullInt(strUserID);
            info.created_when = dtNow;

            tax.Insert(info);
        }

        protected void cmdUpdate_Click(object sender, EventArgs e)
        {
            M_FIM_MAS_CalulateTaxs info = new M_FIM_MAS_CalulateTaxs();
            string strEmpTaxSeq = lblEmpTaxSeq.Text;
            string strPayYear = txtPayYear.Text;
            string strChildCount = txtChildCount.Text;
            string strChildEdu = txtChildEdu.Text;
            string strChildNonEdu = txtChildNonEdu.Text;
            string strContributePerMax = txtContributePerMax.Text;
            string strDisabled = txtDisabled.Text;
            string strExpenseMax = txtExpenseMax.Text;
            string strExpensePer = txtExpensePer.Text;
            string strIns1Max = txtIns1Max.Text;
            string strIns2Max = txtIns2Max.Text;
            string strLoanMax = txtLoanMax.Text;
            string strLtfMax = txtLtfMax.Text;
            string strLtfPerMax = txtLtfPerMax.Text;
            string strOverAge = txtOverAge.Text;
            string strOverAgeAmount = txtOverAgeAmount.Text;
            string strParent = txtParent.Text;
            string strParentInsMax = txtParentInsMax.Text;
            string strReduce = txtReduce.Text;
            string strReserve1Max = txtReserve1Max.Text;
            string strReserve2Max = txtReserve2Max.Text;
            string strReserve2PerMax = txtReserve2PerMax.Text;
            string strReserveGovOfficeMax = txtReserveGovOfficeMax.Text;
            string strRmfMax = txtRmfMax.Text;
            string strRmfPerMax = txtRmfPerMax.Text;
            string strSubEduPer = txtSubEduPer.Text;
            string strSubEduPerMax = txtSubEduPerMax.Text;
            string strSubSportPer = txtSubSportPer.Text;
            string strSubSportPerMax = txtSubSportPerMax.Text;
            string strTaxMax1 = txtTaxMax1.Text;
            string strTaxMax2 = txtTaxMax2.Text;
            string strTaxMax3 = txtTaxMax3.Text;
            string strTaxMax4 = txtTaxMax4.Text;
            string strTaxMax5 = txtTaxMax5.Text;
            string strTaxPer1 = txtTaxPer1.Text;
            string strTaxPer2 = txtTaxPer2.Text;
            string strTaxPer3 = txtTaxPer3.Text;
            string strTaxPer4 = txtTaxPer4.Text;
            string strTaxPer5 = txtTaxPer5.Text;
            string strUserID = Session["EmpSeq"].ToString();
            DateTime dtNow = DateTime.Now;

            info.cal_tax_seq = Convert.ToInt32(strEmpTaxSeq);
            info.child_count = main.ConvertNullInt(strChildCount);
            info.child_edu = main.ConvertNullDouble(strChildEdu);
            info.child_non_edu = main.ConvertNullDouble(strChildNonEdu);
            info.contribute_per_max = main.ConvertNullDouble(strContributePerMax);
            info.disabled = main.ConvertNullDouble(strDisabled);
            info.expense_max = main.ConvertNullDouble(strExpenseMax);
            info.expense_per = main.ConvertNullDouble(strExpensePer);
            info.ins_1_max = main.ConvertNullDouble(strIns1Max);
            info.ins_2_max = main.ConvertNullDouble(strIns2Max);
            info.loan_max = main.ConvertNullDouble(strLoanMax);
            info.ltf_max = main.ConvertNullDouble(strLtfMax);
            info.ltf_per_max = main.ConvertNullDouble(strLtfPerMax);
            info.over_age = main.ConvertNullInt(strOverAge);
            info.over_age_amount = main.ConvertNullDouble(strOverAgeAmount);
            info.parent = main.ConvertNullDouble(strParent);
            info.parent_ins_max = main.ConvertNullDouble(strParentInsMax);
            info.pay_year = main.ConvertNullInt(strPayYear);
            info.reduce = main.ConvertNullDouble(strReduce);
            info.reserve_1_max = main.ConvertNullDouble(strReserve1Max);
            info.reserve_2_max = main.ConvertNullDouble(strReserve2Max);
            info.reserve_2_per_max = main.ConvertNullDouble(strReserve2PerMax);
            info.reserve_gov_office_max = main.ConvertNullDouble(strReserveGovOfficeMax);
            info.reserve_teacher_max = 0;
            info.rmf_max = main.ConvertNullDouble(strRmfMax);
            info.rmf_per_max = main.ConvertNullDouble(strRmfPerMax);
            info.sup_edu_per = main.ConvertNullDouble(strSubEduPer);
            info.sup_edu_per_max = main.ConvertNullDouble(strSubEduPerMax);
            info.sup_sport_per = main.ConvertNullDouble(strSubSportPer);
            info.sup_sport_per_max = main.ConvertNullDouble(strSubSportPerMax);
            info.tax_max1 = main.ConvertNullDouble(strTaxMax1);
            info.tax_max2 = main.ConvertNullDouble(strTaxMax2);
            info.tax_max3 = main.ConvertNullDouble(strTaxMax3);
            info.tax_max4 = main.ConvertNullDouble(strTaxMax4);
            info.tax_max5 = main.ConvertNullDouble(strTaxMax5);
            info.tax_per1 = main.ConvertNullDouble(strTaxPer1);
            info.tax_per2 = main.ConvertNullDouble(strTaxPer2);
            info.tax_per3 = main.ConvertNullDouble(strTaxPer3);
            info.tax_per4 = main.ConvertNullDouble(strTaxPer4);
            info.tax_per5 = main.ConvertNullDouble(strTaxPer5);

            info.updated_by = main.ConvertNullInt(strUserID);
            info.updated_when = dtNow;

            tax.Update(info);
        }

        protected void cmdDup_Click(object sender, EventArgs e)
        {
            string strPayYear = txtPayYear.Text;
            string strDupPayYear = txtDupPayYear.Text;
            M_FIM_MAS_CalulateTaxs info = tax.GetInfoFromYear(strDupPayYear);
            string strUserID = Session["EmpSeq"].ToString();
            DateTime dtNow = DateTime.Now;

            if (cmdInsert.Visible)
            {
                info.pay_year = main.ConvertNullInt(strPayYear);
                info.created_by = main.ConvertNullInt(strUserID);
                info.created_when = dtNow;

                tax.Insert(info);
            }
            else
            {
                string strEmpTaxSeq = lblEmpTaxSeq.Text;
                info.cal_tax_seq = Convert.ToInt32(strEmpTaxSeq);
                info.pay_year = main.ConvertNullInt(strPayYear);
                info.updated_by = main.ConvertNullInt(strUserID);
                info.updated_when = dtNow;

                tax.Update(info);
            }

            LoadData(strPayYear);
        }

        protected void txtPayYear_TextChanged(object sender, EventArgs e)
        {
            string strPayYear = txtPayYear.Text;

            if (strPayYear.Length == 4)
            {
                LoadData(txtPayYear.Text);
            }
        }
        
        //==========================================================================
    }
}
